﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TCCHWLib
{
    public enum MESI { Modified, Exclusive, Shared, Invalid, WriteSet }

    public class CacheEntry : MemoryEntry
    {
        private int m_Address;
        private MESI m_MESIBits;

        public MESI MESIBits
        {
            get { return m_MESIBits; }
            set { m_MESIBits = value; }
        }

        public int Address
        {
            get { return m_Address; }
            set { m_Address = value; }
        }
        public override object Value
        {
            get { return m_Value; }
            set { m_Value = value; }
        }


        public CacheEntry(int address, object value, MESI MESIbits)
            : base(value)
        {
            m_Address = address;
            m_Value = value;
            m_MESIBits = MESIbits;
        }
        public CacheEntry(int address) :
            this(address, null, MESI.Invalid)
        {
        }
        public CacheEntry(int address, object value) :
            this(address, value, MESI.Invalid)
        {
        }

        public override string ToString()
        {
            string value = "";

            if (m_Value == null)
                value += String.Format("{0,1}", "  Null Value\t");
            else
                value += String.Format("{0,1}", "\t" + m_Value.ToString());

            string mesi = "[";
            if (m_MESIBits == MESI.Exclusive)
                mesi += "E";
            if (m_MESIBits == MESI.Invalid)
                mesi += "I";
            if (m_MESIBits == MESI.Modified)
                mesi += "M";
            if (m_MESIBits == MESI.Shared)
                mesi += "S";
            if (m_MESIBits == MESI.WriteSet)
                mesi += "W";
            mesi += "]";

            return String.Format(" {0, -16}\t{1}", value, mesi);
        }
    }
}
